#include <iostream>
#include <string>
#include <SimpleAmqpClient/SimpleAmqpClient.h>

int main()
{
    using std::string;
    using namespace AmqpClient;

    string uri = "amqp://guest:guest@localhost:5672/%2f";
    AmqpClient::Channel::ptr_t channel = AmqpClient::Channel::CreateFromUri(uri);

    AmqpClient::Envelope::ptr_t envelope;
    const std::string& q = "direct.queue1";

    // 如果队列中有消息，将消息放入到evelope中，并返回true
    // 如果队列中没有消息，BasicGet会立刻返回false
    // if(!channel->BasicGet(envelope, q)){
    //     std::cout<<"false\n";
    //     return false;
    // }

    // if (envelope && envelope->Message()) {
    //     std::cout << envelope->Message()->Body() << "\n";
    // }

     channel->BasicConsume(q);

     for(;;) {
         Envelope::ptr_t envelope = channel->BasicConsumeMessage();
         // 打印消息
         if (envelope && envelope->Message()) {
             std::cout << envelope->Message()->Body() << "\n";
         }
     }

}


